var SKYLINE_DOMAIN = '/skyline/';
var SKYLINE_VIEWNOTIFICATION = SKYLINE_DOMAIN + "notice/view/";
Date.prototype.getYear = Date.prototype.getFullYear;
var portraitPath = SKYLINE_DOMAIN+"image/";
var smileys = [ "angel_smile", "angry_smile", "broken_heart", "confused_smile",
        		"cry_smile", "devil_smile", "embaressed_smile" ];
var smileysChn = [ "天使", "生气", "心碎", "迷惑", "哭泣", "恶魔", "尴尬" ];
var smileysPath = SKYLINE_DOMAIN+"/plugin/ckeditor/plugins/smiley/images/";
var sorryGifPath = SKYLINE_DOMAIN+"/img/commons/sorry_small.gif";

function doAjax(postUrl, postData, successFunc, errorFunc, beforeSendFunc,
		completeFunc) {
	jQuery.ajax({
		type : "POST",
		global : false,
		contentType : "application/x-www-form-urlencoded;charset=UTF-8",
		url : postUrl,
		data : postData,
		beforeSend : beforeSendFunc,
		success : successFunc,
		error : errorFunc,
		complete : completeFunc
	});
}

Date.prototype.format = function(style){
	var o = {
		    "M+" : this.getMonth() + 1, // month
		    "d+" : this.getDate(),      // day
		    "h+" : this.getHours(),     // hour
		    "m+" : this.getMinutes(),   // minute
		    "s+" : this.getSeconds(),   // second
		    "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		    "S" : this.getMilliseconds() // millisecond
	}
	if(/(y+)/.test(style)){
		    style = style.replace(RegExp.$1,
		    (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for(var k in o){
	   if(new RegExp("("+ k +")").test(style)){
	      style = style.replace(RegExp.$1,
	    		RegExp.$1.length == 1 ? o[k] :
		        ("00" + o[k]).substr(("" + o[k]).length));
		    }
	}
	return style;
};

Vote = {
	articleUpUrl : SKYLINE_DOMAIN + "/article/up/",
	articleDownUrl : SKYLINE_DOMAIN + "/article/down/",
	shareUpUrl : SKYLINE_DOMAIN + "/share/up/",
	shareDownUrl : SKYLINE_DOMAIN + "/share/down/",
	up : function(upA, upFont, downA, downFont, disableStyle, id, up, type) {
		Vote.updateUpOrDown(upA, upFont, downA, downFont, disableStyle, id, up,
				true, type);
	},
	down : function(upA, upFont, downA, downFont, disableStyle, id, down, type) {
		Vote.updateUpOrDown(upA, upFont, downA, downFont, disableStyle, id,
				down, false, type);
	},
	updateUpOrDown : function(upAValue, upFontValue, downAValue, downFontValue,
			disableStyle, id, num, isUp, type) {
		var updateUrl = "";
		if (type == "ARTICLE") {
			if (isUp) {
				updateUrl = Vote.articleUpUrl + id + ".html";
			} else {
				updateUrl = Vote.articleDownUrl + id + ".html";
			}
		} else if (type == "SHARE") {
			if (isUp) {
				updateUrl = Vote.shareUpUrl + id + ".html";
			} else {
				updateUrl = Vote.shareDownUrl + id + ".html";
			}
		}
		$.ajax({
			url : updateUrl,
			data : null,
			type : "POST",
			dataType : "json",
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : function(msg) {
				// alert(upFont);
				var upFont = document.getElementById(upFontValue);
				var upA = document.getElementById(upAValue);
				upA.href = "javascript:;";
				var downFont = document.getElementById(downFontValue);
				var downA = document.getElementById(downAValue);
				downA.href = "javascript:;";
				if (isUp) {
					upFont.innerHTML = (num + 1);
				} else {

					downFont.innerHTML = (num + 1);
				}
			}
		});
	}
}